package com.bskj.common.service.impl;

import java.util.List;

import com.bskj.common.bean.model.BaseModel;
import com.bskj.common.dao.core.FindRequestEntity;
import com.bskj.common.dao.core.Page;
import com.bskj.common.service.IBaseService;

/**
 * 
 * @author lishi
 * @date 2017-11-29 上午11:14:23
 * @param <T>
 */
public abstract class BaseServiceImpl<T extends BaseModel> implements
		IBaseService<T> {
	public void insert(T t) {
		getBaseDao().insert(t);
	}

	public int update(T t) {
		return getBaseDao().update(t);
	}

	@Override
	public List<T> find(FindRequestEntity param) {
		return getBaseDao().find(param);
	}

	@Override
	public T get(Integer id) {
		return getBaseDao().get(id);
	}

	@Override
	public int del(Integer id) {
		return getBaseDao().del(id);
	}

	@Override
	public Page<T> page(FindRequestEntity param) {
		if(param.getPageNo() == null) {
			param.setPage(1, 10);
		}
		Page<T> pageResult = new Page<T>();
		pageResult.setPage(param.getPageNo());
		pageResult.setPageSize(param.getPageSize());
		
		List<T> list = getBaseDao().find(param);
		int count = getBaseDao().count(param.getWhereList());
		pageResult.setList(list);
		pageResult.setTotalRow(count);
		return pageResult;
	}
}
